2017-07-25 162 views
1

我的jQuery代碼是:(這將觸發模式按鈕點擊)通過模式按鈕操作設置的元素值不工作在jQuery中?

$(document).on('click', '.js-modal-remove-button', function() { 
    $('#code-output').attr('da-url',"1111"); 
}); 

我的HTML代碼:

<input type="hidden" name="problemCode" id="code-output" da-url=2/> 

問題是,在我的網頁上的按鈕,就這按鈕點擊模式打開,並在模式中還有一個按鈕包含類 js-modal-remove-button 上的動作,我需要設置我的主頁(其上模式打開按鈕存在)da-url值

+0

是.js文件模態-等工作的行動點擊?做一個console.log以確保它正在調用它。 – Roy

+0

是的,它的工作 –

+0

,你是不是重複ID#代碼輸出不止一次正確?...也許,如果你創建一個新的類綁定..像$(文檔).on('點擊','.sendDaUrl' ,function(){... – Roy

回答

0

剛和另一個類的按鈕,然後使用這個jQuery
HTML

<button class="js-modal-remove-button model_button_class"></button> 

jQuery的

$(document).on('click', '.js-modal-remove-button .model_button_class', function() { 
    $('#code-output').attr('da-url',"1111"); 
}); 

這裏.model_button_class是另一個類。
我的事情會幫助你。

0

試試這個:

$('.js-modal-remove-button .model_button_class').on('click',function(){ 
    $('#code-output').attr('da-url',"1111"); });