我尝试在代码中使用jQuery。我是初学者。我尝试用函数“.replaceWith()”来做到这一点。 我首先尝试将颜色更改为红色。 我做了什么: http://jsfiddle.net/kzVSt/300/
$(document).ready(){
$("#del").click(function(){
$("#del").replaceWith("<input type='button' id='del1' value='dsjkdsa'>");
});
};
#del1{
color:red;
}
<input type="button" id="del" value="button">
答案 0 :(得分:1)
使用dataGridView
试
$(document).ready(function() { ... });
&#13;
$(document).ready(function() {
$("#del").click(function(){
$("#del").replaceWith("<input type='button' id='del1' value='dsjkdsa'>");
});
});
&#13;
#del1{
color:red;
}
&#13;
答案 1 :(得分:0)
ready
函数的正确语法如下所示:
UUID
答案 2 :(得分:0)
好像您错误地使用了ID和类。这里有几个提示
而不是:
$(document).ready(function(){
别名为
jQuery(function($){
这是$ .ready()处理程序的短代码jQuery别名。
接下来,如果将元素替换为另一个元素,则将销毁绑定到该元素的所有事件。相反,切换班级。
如果要更新值,请在jQuery对象上定位.val()
方法(您可以通过$(this)
引用其事件内的元素。
最后,如果要添加一些CSS颜色而不是更改ID,请使用类。
jQuery(function(){
$('#del').on('click', function(){
$(this).addClass('color-red');
$(this).val('dsjkdsa');
});
});