如何解决预期的表达式,在jquery中得到了脚本的结束 [英] How to solve expected expression ,got end of script in jquery

查看:45
本文介绍了如何解决预期的表达式,在jquery中得到了脚本的结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了预期的表达式,将数据一个函数传递给另一个函数时得到了脚本错误的结束。









i got expected expression, got end of script error when pass the data one function to another function.




cont += '<p><a href="javascript:onDisp('+filepath+ ')">' + DocHeader + '</a></p>';

推荐答案

问题是你没有传递文件路径变量正确。目前,当它传递给函数 onDisp 时,它将被视为一个变量,然后它将通过表达式错误,因为传递的数据格式不正确。



所以,假设您的文件路径如下:



The issue is you are not passing the filepath variable properly. Currently when its passed to the function onDisp it would be considered as a variable and then it would through an expression error as the data passed is not in correct format.

So, lets say your file path is like:

var filepath = 'C://Test/image.jpj'





但它会被传递为





but it would be passed as

<p><a href="javascript:onDisp(C://Test/image.jpj)">asasa</a></p>





自从适当的qoutes到文件路径变量是没有提供。



所以,你可以解决它: -





since the proper qoutes to the filepath variable is not provided.

So, you can resolve it like:-

cont += '<p><a href="javascript:onDisp(\''+filepath+ '\')">' + DocHeader + '</a></p>';





然后你就可以在onDisp里面测试它了:





Then you can test it inside the onDisp like:

function onDisp(filepath){
    alert(filepath);

    // your code goes here
}





现在这将显示正确的输出。



This will display correct output now.


这篇关于如何解决预期的表达式,在jquery中得到了脚本的结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆