js中拼接html文档之onclick函数处理

来源:互联网 发布:淘宝退款会影响信誉吗? 编辑:程序博客网 时间:2024/06/09 18:43
拼接html文档时,对于onclick如何拼接:

1.直接拼接onclcik函数 

function setNameplate(obj){var str = "";var name = $(obj).prev("span").text();str = '<input type="text" id="nameplate" value='+name+'>'+ '<button class="btn-confirm" onclick="confirmNameplate(this)">确定</button>'+ '<button class="btn-cancel" onclick="cancelNameplate(this,\''+name
+ '\')">取消</button>';$(obj).parent().html(str);}

2.若onclick函数参数有特殊字符,传参数会有问题,可以采取元素上加属性的方法,把参数传出去。

//视频if(executeInfo[i].file_type == "3" || executeInfo[i].record_type == "1"){console.log(executeInfo[i].folder+ ','+executeInfo[i].file_name);videostr = videostr + '<tr class="videoTr">' +                '<td style="width: 10%" title="'+executeInfo[i].create_user+'">' + executeInfo[i].create_user + '</td>' +                '<td style="width: 10%" title="'+executeInfo[i].device_id +'">' + executeInfo[i].device_id + '</td>' +                '<td style="width: 15%" title="'+executeInfo[i].execute_time+'">' + executeInfo[i].execute_time + '</td>' +                '<td style="width: 20%" title="'+executeInfo[i].descr+'">' + executeInfo[i].descr + '</td>' +                '<td style="width: 15%" title="'+executeInfo[i].beginTime+'">' + executeInfo[i].beginTime + '</td>' +                '<td style="width: 15%" title="'+executeInfo[i].endTime+'">' + executeInfo[i].endTime + '</td>' +                '<td style="width: 10%" title="'+executeInfo[i].upload_name+'">' + executeInfo[i].upload_name + '</td>' +                '<td style="width: 5%; text-align: center;">' +                '<a class="play" folder="' + executeInfo[i].folder + '" file_name="' + executeInfo[i].file_name+ '">'+'播放' +'</a>'+'</td>' +                '</tr>';}


js函数:

$(document).on("click", "tr.videoTr a.play", function() {var folder = $(this).attr("folder");var file_name = $(this).attr("file_name");videojs("video_play",{}).ready(function(){    var myPlayer = this;    myPlayer.src("../"+folder+"/"+file_name);    myPlayer.play();});return false;});



阅读全文
0 0
原创粉丝点击