我有以下代码:插入元件与jQuery的DIV,追加不工作
$('input[id$="txtTecnicas"]').bind('keypress', function (e) {
//if user presses enter
if (e.keyCode == 13) {
//cancel asp.net postback
e.preventDefault();
//if value of textbox is not empty
if ($(this).val() != "") {
//Save value into valueTec
var valueTec = $(this).val();
//Clear textbox value
$(this).val("");
//Create tag div to insert into div
var texthtml = '<span class="tag" title="' + valueTec + '">' + valueTec + ' <a>x</a><input type="hidden" value="1" name="tags"></span>';
//Append the new div inside tecTagHolder div
$('[id$="tecTagHolder"]').append(texthtml);
}
}
});
但是,它不插入代码到tecTagHolder格,并且由于它需要插入tecTagHolder很多的div,一个每次用户按下回车键,我都不能使用.html()
命令,但是附加它后面不会附加“Hello”字符串!有什么可能是错的?非常感谢!
这是asp.net那里的对象更改名称时,对象已经RUNAT =“服务器”,使用$(“#tecTagHolder”)是不会工作。 – 2013-03-12 23:50:26
修正了,试试。 – tymeJV 2013-03-12 23:51:38
你是否收到错误?你确定你的选择器实际上是抓取你想要的DOM元素吗?没有你的标记,很难看出什么是错的。 – iGanja 2013-03-12 23:52:10