我正在爲一個網站製作一個管理屏幕,當你發佈文章時。我已經做到了,所以表格中包含了所有帖子的價值。jQuery .html()不能在if語句中工作
<table>
<tr>
<th>Post Title</th>
<th>Post Content</th>
<th>Tag</th>
</tr>
<tr>
<td id="examplePostTitle">Post Title</td>
<td id="examplePostContent">First 35 charecters of post........</td>
<td id="examplePostTag">Post Tag</td>
<td class="postEditButton" id="examplePostButton">edit</td>
</tr>
</table>
我已經用jquery編寫了一些javascript,這樣當用戶單擊編輯行時就會填充輸入框。
var click = 1;
if (click == 1) {
$('#examplePostButton').click(function() {
$('#examplePostTitle').html('<input type="text" value="Post Title" size="10"/>');
$('#examplePostContent').html('<input type="text" value="First 35 characters of post........" size="20"/>');
$('#examplePostTag').html('<select><option>Animation</option><option>Programing</option> <option>Robotics</option><option>Other</option></select>');
click = 2;
});
}
if (click == 2) {
$('#examplePostButton').click(function() {
$('#examplePostTitle').html('Post Title');
$('#examplePostContent').html('First 35 characters of post........');
$('#examplePostTag').html('Post Tag');
click = 1;
});
}
出於某種原因,你可以單擊編輯按鈕一次,它變成輸入框。然後當你第二次點擊它時,它不會改變變量,並且不會恢復到非輸入框。我用多個js和jquery驗證器檢查了我的代碼,所以我不太確定爲什麼第二個點擊函數不起作用。
tl:dr:
我有一些JavaScript和jQuery代碼,沒有工作,幫助。
Jsfiddle
YES的。舊的brainfart再次罷工。謝謝。 –
請注意,在這裏布爾似乎比整數更多。 –
[**下面是這個解決方案的一個小工具**](http://jsfiddle.net/VDPFa/) - 你可能想考慮不把HTML放在字符串中 - 它會非常快速地混亂。 –