$.each(data.root, function(i, item) {
var title = "";
if(item.title.length > 10)
title = item.title.substring(0,10);
else
title = item.title;
$("#taskData").append("<tr height=\"22\"><td colspan=\"2\"><a style=\"cursor:pointer\"><a title='"
+ item.title + "'>[" + item.fType +"]"+ title +"</a></td><td width=\"120\" colspan=\"2\" style='color:#888'>" + item.createTime + "<td>")
});
怎么给title一个点击事件
js
------解决方案--------------------
后面跟着加click就可以。例如<a click='abc()' title='"
+ item.title + "'>[" + item.fType +"]"+ title +"</a>
function abc(){
}
------解决方案--------------------
你上面a 标签多写一个吧。
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function() {
var o = [];
o.push("1");
o.push("2");
o.push("3");
$.each(o,
function(i, item) {
$("#taskData").append("<tr height=\"22\"><td colspan=\"2\"><a
style=\"cursor:pointer\" title='" + item.title + "'>[" + item + "]" + item + "</a></td><td width=\"120\" colspan=\"2\"
style='color:#888'>"
+ item + "<td>")
});
$("a").bind("click",
function() {
alert($(this).html());
});
});
</script>
</head>
<body>
<table id="taskData">
</table>
</body>
</html>
------解决方案--------------------
直接在你拼接的那串html里面加href就是了。因为a标签有点特殊用href就可以了不用onclick
"<tr height=\"22\"><td colspan=\"2\"><a style=\"cursor:pointer\"><a title='"
+ item.title + "' href=\"javascript:xxx();\">[" + item.fType +"]"+ title +"</a></td><td width=\"120\" colspan=\"2\" style='color:#888'>" + item.createTime + "<td>"
function xxx(){....}
------解决方案--------------------
刚刚写了个,给个样版你看看
$(function() {
var markers = null;
$("#searchbtn").click(
function() {
$("#nodelist").html("");
var searchText = $("#searchtext").val();
var url = $("#path").val() + "/map_search.do";
$.post(url, {
"name" : searchText
}, function(data) {
if (data.items == "") {
$("#nodelist").html("没有匹配的数据").css("color", "red");
return;
}
$("#nodelist").css("color", "blue").append(
"<table id='nodetable'><thead><tr><th>gid</th>"
+ "<th>name</th>" + "<th>kind</th>"
+ "<th>geom</th>" + "<th>经度</th>"
+ "<th>纬度</th>"
+ "</tr></thead></table>");
var table = $("#nodetable");
if (markers != null) {
map.removeLayer(markers);
}
markers = new OpenLayers.Layer.Markers("Markers");
map.addLayer(markers);
$.each(data.items, function(i, v) {
var gid = v.gid == null ? "" : v.gid;
var name = v.name == null ? "" : v.name;
var kind = v.kind == null ? "" : v.kind;