我有一個代碼與link
,當點擊鏈接我想做點什麼,但我不知道爲什麼點擊不起作用,並且警報甚至不會啓動jquery onclick不起作用
jQuery代碼
$(document).ready(function(){
$("#editConcept").on('click','ecAddLink',function(){
$.getJSON("http://localhost/Mar7ba/Ontology/getAllConcepts/TRUE",function(data){
alert("William Roma");
var options = '';
options+="<option>Select Concept</option>";
for(var i=0;i<data.length;i++){
options += "<option>"+data[i]+"</option>";
}
$.getJSON("http://localhost/Mar7ba/Ontology/getAllRelations/TRUE",function(data){
var options2 = '';
options2+="<option>Select Concept</option>";
for(var i=0;i<data.length;i++){
options2 += "<option>"+data[i]+"</option>";
}
$("#editConcept ul li:last").before('\
<li>\n\
<p>\n\
<label>Concept</label>\n\
<select name="newConcepts[]">'+options+'</select>\n\
<span class="errorMessage"></span>\n\
</p>\n\
<p>\n\
<label>Relations</label>\n\
<select name="newRelations[]">'+options2+'</select>\n\
<span class="errorMessage"></span>\n\
<a href="#" class="removeA">delete</a>\n\
</p>\n\
</li>');
});
});
});
});
HTML代碼
<div id="editConcept" class="container">
<form id="ecForm" method="POST" action="<?php echo URL; ?>Ontology/conceptEdit">
<ul>
<li>
<label>Select Concept</label>
<select class="ConceptSelector1"></select>
<span class="errorMessage"></span>
</li>
<li id="ecOldRelations">
<p>
<label>Old Relations</label>
</p>
</li>
<li id="ecNewRelations">
<label>New Relations</label>
<a href="#" class="smallLink" id="ecAddLink">add new relations</a>
</li>
<li>
<input type="submit" class="button1" value="save"/>
</li>
</ul>
</form>
</div>
the link has an id = ecAddLink
是是,謝謝你,很抱歉,真的1小時試圖找出錯誤,但還沒有出現,我的腦海裏,錯誤很容易這樣 –
我是jquery的新手,是的,你是對的,我也不喜歡把html放在字符串中,謝謝你對隱藏元素的建議,我會試着學習它 –
我相信你絕對是URL談論可能由服務器端產生。 – VisioN