我是Jquery的新手,正在学习它。我创建了一个非常简单的html文件,并带有一个动态添加新文本字段的按钮。我面临的问题是,添加新文本字段时,它不会像第一个文本字段那样工作,它允许通过加载的“viettypingplus.js”脚本键入越南字符。此脚本不适用于通过“添加文本字段”按钮动态添加的第二个文本字段。如何将加载的脚本应用到动态添加的元素?
我一直在寻找,但没有找到解决办法。请帮忙。
以下是我的html: 在第一个文本字段中输入“a6”得到:“ - 但在第二个文本字段中,我得到”a6“。
非常感谢您的帮助。
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome - {% block title %}{% endblock %}</title>
<title>Viettyping Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
., body, td, th { font-family:Arial; }
</style>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://vietdev.sourceforge.net/jscript/viettyping/viettypingplus.js"></script>
</head>
<body bgcolor="#F0F0D0">
<center>
<h3>Vietnamese Typing</h3>
<form id="TestForm">
Text input: <input name="xxx">
<input id="AddText" value="Add Text Field" onclick="" type="button">
</form>
</center>
<br>
<script>
$("#AddText").click(function(e){
$("#TestForm").append($('<td><b>Text input: <input name="test" type="text"/></b></td>'));
});
</script>
</body>
</html>
添加新元素后,您可能需要重新运行[插件](http://vietdev.sourceforge.net/jscript/viettyping/)。 – Blazemonger 2014-08-31 03:49:26
@ jfriend00你应该把这些建议放入答案而不是评论。 – drewish 2014-08-31 04:56:16
@drewish - 你是对的 - 我添加了一个答案。 – jfriend00 2014-08-31 05:08:31