JavaScript链接不起作用
javascript link not working
这让我有点疯狂。 Javascript链接应该触发函数来填充div。 但不起作用。
.js
function showNotes(notes,id) {
var notes = '<form action="editnotes.php" method="post"><textarea>'+notes+'</textarea><input type="hidden" name="id" value="'+id+'"><input type="submit" name="submit" value="Save Notes"></form>';
var target = 'notebox';
alert(id);
document.getElementById(target).innerHTML = notes;
return false;
}
.html
<a href='#' onclick='showNotes('hi there','143');'><small>Show Notes</small></a>
<div id="notebox"></div>
将onclick
属性值括在双引号中,以便单引号指定字符串中的字符串。
onclick="showNotes('hi there','143');"
http://jsfiddle.net/77CKx/
Shredder抓住了问题的核心。您有嵌套引号。但是,内联JS并不酷。用脚本做,问题就消失了。http://robertnyman.com/2008/11/20/why-inline-css-and-javascript-code-is-such-a-bad-thing/
.HTML
<a href="#" id="shownotes"><small>Show Notes</small></a>
.JS
document.getElementById('shownotes').onclick = function() {
showNotes('hi there', '143');
return false;
}
似乎您正在通过将单个撇号用于函数参数来破坏 onclick。
尝试
<a href='#' onclick="showNotes('hi there','143');"><small>Show Notes</small></a>
工作代码:
showNotes = function (notes,id) {
var notes = '<form action="editnotes.php" method="post"><textarea>'+notes+'</textarea><input type="hidden" name="id" value="'+id+'"><input type="submit" name="submit" value="Save Notes"></form>';
var target = 'notebox';
alert(id);
document.getElementById(target).innerHTML = notes;
return false;
}
<a href='#' onclick="showNotes('hi there','143');"><small>Show Notes</small></a>
<div id="notebox"></div>
您也可以在此处查看它的工作:http://jsfiddle.net/ZMZGk/13/
相关文章:
- 我的下拉菜单中的链接不起作用
- JavaScript链接在点击时不起作用;函数在页面加载时工作
- 链接上的IE10 jquery句柄单击事件不起作用
- mouseover和mouseleave文本颜色更改在指令链接中不起作用
- Ajax:Ajax响应中的链接不起作用
- jQuery Mobile到其他页面的锚链接不起作用
- HTML5视频链接在Chrome中不起作用
- Datatable Javascript链接在第2页不起作用
- 指向的超链接刚刚赢得'不起作用
- 链接到手风琴中的另一个选项卡,嵌入的链接将不起作用
- jquery animation.scrollTop()在mdl链接中不起作用
- 在jQuery中链接时CSS属性不起作用
- 从HTML链接时,Javascript文件不起作用
- iframe resizer内部的锚点链接不'不起作用
- 为什么不'使用此JavaScript将文本替换为不起作用的链接
- 外部JavaScript链接不起作用
- 淡入淡出链接悬停不起作用
- 当图像和链接是 json 对象属性的值时,它们不起作用
- 对链接的 svg 进行动画处理不起作用;内联时工作正常
- AngularJS路由不起作用:链接点击时没有事件,没有$routeParams