2013-07-30 72 views
-1

繼續明天就點擊這個「X」符號,我想刪除列表質疑jquery刪除行上點擊不工作?

function n() { 
    $('.m').on('click',function() { 
    var id = $(this).closest("tr").find(".t").text(); 
    var p= $(this).closest("tr").find(".t1").text(); 
    $('#c').append('<li class='li'>',id,<span class='c'>'"X"'</span>','</li>'); 
    }); 
} 
<style> 
.c:hover 
{ 
color:red; 
} 
.li 
{ 
} 
<script type="text/javascript"> 
$(document).on('click','.c',function()   
{ 

    $(this).closest("li").remove() 
    alert("ok"); 
}); 

</script> 

,在警報「確定」打印,但刪除功能不能正常工作,爲什麼?

+0

有很多語法錯誤的代碼。請至少提供運行代碼。我不知道你的代碼中是否真的存在這些錯誤,或者你只是在這裏潦草地複製你的代碼。 –

+1

風格標籤沒有關閉 –

回答

1

一定要在標記中添加適當的scriptstyle標記。它們也應該適當關閉,例如style標籤未封閉。未封閉的style標籤可能會導致問題。

同樣在script之內有單引號嵌套錯誤。如果需要,例如在標記中,使用外部單引號表示字符串文字和字符串文字中的雙引號。它也似乎你試圖連接使用,但是在Javascript中,連接運算符是+

<script> <!-- I didn't exist /> 
function n() { 
    $('.m').on('click',function() { 
    var id = $(this).closest("tr").find(".t").text(); 
    var p= $(this).closest("tr").find(".t1").text(); 

    //Concatenation and String literal fixed here 
    $('#c').append('<li class="li">' + id + '<span class="c">X</span></li>'); 
    }); 
} 
</script> 

<style> 
    .c:hover 
    { 
     color:red; 
    } 

    .li 
    { 
    } 
</style><!-- I wasn't closed --> 

<script type="text/javascript"> 
$(document).on('click','.c',function()   
{ 

    $(this).closest("li").remove() 
    alert("ok"); 
}); 

</script> 
+0

--ya在這裏錯誤地這些語法錯誤,bt在我的例子中是正確的書面,但在警報確定打印但列表行不刪除爲什麼? – user2598718

0

你似乎已經忘記了刪除()後分號叫

+0

分號是可選的。在某些情況下,缺少分號可能會導致意外的行爲,但這不是其中之一。 –

+0

汽車安全帶也是如此:-P ......如果你正在調試這個,例如,在一個使用Visual Studio的asp.net頁面中,你有可能在你的手上有一個頭部抓手 –