2017-07-25 159 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"); });