使用javascript变量

Jef*_*eff 0 javascript variables

我在使用此脚本时遇到问题,将变量识别为变量.该脚本的重要部分如下:

    var content = 'imagereims';
    var ms = content.substring(5);
    $.get("../msimages/image.php", {ms: 'ms', pid: '<?php echo "$pid" ?>'}
    );
Run Code Online (Sandbox Code Playgroud)

我希望脚本将变量识别msreims,但是当页面显示时,它无法识别变量的内容.它只是重复ms.我试过写没有单引号和双引号的变量.我得到了相同的结果.

有什么建议.谢谢

bea*_*mit 5

你想在'ms'上留下引号.试试这个:

var content = 'imagesreims'
var ms = content.substring(4);
$.get("../msimages/image.php", {ms: ms, pid: '<?php echo "$pid" ?>'});
Run Code Online (Sandbox Code Playgroud)

'ms'表示使用此字符串文字作为值.

您还需要一个不同的子字符串.试试content.substring(6).content.substring(4)将产生'esreims'.

正如另一个答案中提到的那样,你错过了);最后,我已经把它包含在我的答案中了.