使用 html 代码附加字符串
我正在尝试构建一个片段,稍后将其插入到更大的代码片段中。
到目前为止一切正常,但有一个问题: 我还没有弄清楚如何实现 ONCHANGE 部分。 该值已成功检测到,但我只是没有得到良好的 index.php?day=23424234 组合。我想这与转义字符有关?
有人会帮助我吗?
$dayChoser = ' <form name="day">
<select ONCHANGE="location = index.php?day=this.options[this.selectedIndex].value;">
';
foreach ($tageArray as $ts) {
$tempDay = date('m/d/Y', $ts);
$dayChoser.='<option value=' . $ts . '>' . $tempDay . '</option>';
}
$dayChoser.='</select> </form>';
I'm trying to build a snippet which will later be inserted into a bigger piece of code.
Everythings working fine so far, but there's one problem:
I have not figured out how to implement the ONCHANGE-part.
The value is detected successfully, but I just don't get a fine index.php?day=23424234 combination. I suppose it's something about escape characters?
Would anyone help me?
$dayChoser = ' <form name="day">
<select ONCHANGE="location = index.php?day=this.options[this.selectedIndex].value;">
';
foreach ($tageArray as $ts) {
$tempDay = date('m/d/Y', $ts);
$dayChoser.='<option value=' . $ts . '>' . $tempDay . '</option>';
}
$dayChoser.='</select> </form>';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这更多是一个 Javascript 语法问题。
index.php?day=
部分应该是一个字符串,this.
之后的所有内容都是一个表达式。HTML属性中JS的引号只需要\转义即可,因为PHP的外引号已经是单引号了。
It's more a Javascript syntax problem. The
index.php?day=
part should be a string, and everything after thethis.
is an expression.The quotes for JS in the HTML attribute just need \ escaping, because the outer quotes for PHP are already single quotes.
尝试更改
为
Try changing
to
您需要在内联 javascript 中将路径放在引号中,然后将其连接到所选值。
用插入符号表示的更改
You need the path in quotes within the in-line javascript, then have it concatenate the selected value.
Changes denoted by carets
您在要设置的位置值周围缺少引号。
';
You are missing quotes around the location value that you want to set.
';