我是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