简体   繁体   English

通过JS变量onchange

[英]Passing through JS variables onchange

I'm trying to pass through three variables ( artistID , albumID and currently selected value) to function player but I keep getting an error each time I try this: 我试图将三个变量( artistIDalbumID和当前选择的值)传递给函数播放器,但是每次尝试执行此操作时,我都会不断收到错误消息:

var carry_else = 'actorID,movieID,this.value'

This is the code as it stands I have been trying to edit var carry_else to no success: 这是目前的代码,我一直在尝试编辑var carry_else失败:

actorID = movie_select.substring(0, movie_select.indexOf(':'));
movieID = movie_select.substring(movie_select.indexOf(':')+1, movie_select.length); 

// this line needs to be edited to var carry_else = 'actorID,movieID,this.value' but doing this doesn't work    
var carry_else = 'this.value,this.value,this.value' 
hstr+="<form><select size='"+count+"' onChange='parent.info(" + carry_else + ");'>";

How can I solve this issue? 我该如何解决这个问题?

Since actorID and movieID appear to be strings, why not put them in as literals: 由于actorID和movieID似乎是字符串,所以为什么不将它们作为文字输入:

function escapeHtml(str) {
  return str.replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/"/g,'&quot;');
};
function quoteString(str) {
  return '"'+str.replace(/"/g,'\\"')+'"';
}

hstr+="<form><select size='"+count+"' onChange='parent.info("+escapeHtml(quoteString(actorID))+","+escapeHtml(quoteString(movieID))+",this.value);'>";

If available, I'd use JSON.stringify() instead of the quoteString function I put above. 如果可用,我将使用JSON.stringify()而不是上面放置的quoteString函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM