使用 html 代码附加字符串

发布于 2024-10-29 14:51:56 字数 540 浏览 4 评论 0原文

我正在尝试构建一个片段,稍后将其插入到更大的代码片段中。

到目前为止一切正常,但有一个问题: 我还没有弄清楚如何实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

几度春秋 2024-11-05 14:51:56

这更多是一个 Javascript 语法问题。 index.php?day= 部分应该是一个字符串,this. 之后的所有内容都是一个表达式。

$dayChoser = ' <form name="day">
    <select ONCHANGE="document.location = \'index.php?day=\' + this.options[this.selectedIndex].value;">
';

HTML属性中JS的引号只需要\转义即可,因为PHP的外引号已经是单引号了。

It's more a Javascript syntax problem. The index.php?day= part should be a string, and everything after the this. is an expression.

$dayChoser = ' <form name="day">
    <select ONCHANGE="document.location = \'index.php?day=\' + this.options[this.selectedIndex].value;">
';

The quotes for JS in the HTML attribute just need \ escaping, because the outer quotes for PHP are already single quotes.

沩ん囻菔务 2024-11-05 14:51:56

尝试更改

<select ONCHANGE="location = index.php?day=this.options[this.selectedIndex].value;">

<select ONCHANGE="window.location = \'index.php?day=\' + this.options[this.selectedIndex].value">

Try changing

<select ONCHANGE="location = index.php?day=this.options[this.selectedIndex].value;">

to

<select ONCHANGE="window.location = \'index.php?day=\' + this.options[this.selectedIndex].value">
記憶穿過時間隧道 2024-11-05 14:51:56
<select ONCHANGE="location = \'index.php?day=\'+this.options[this.selectedIndex].value;">';
                             ^^              ^^^

您需要在内联 javascript 中将路径放在引号中,然后将其连接到所选值。

用插入符号表示的更改

<select ONCHANGE="location = \'index.php?day=\'+this.options[this.selectedIndex].value;">';
                             ^^              ^^^

You need the path in quotes within the in-line javascript, then have it concatenate the selected value.

Changes denoted by carets

送舟行 2024-11-05 14:51:56

您在要设置的位置值周围缺少引号。

$dayChoser = ' <form name="day"><select ONCHANGE="location = \'index.php?day=\' + this.options[this.selectedIndex].value + \';\'">

';

You are missing quotes around the location value that you want to set.

$dayChoser = ' <form name="day"><select ONCHANGE="location = \'index.php?day=\' + this.options[this.selectedIndex].value + \';\'">

';

空城旧梦 2024-11-05 14:51:56
 $dayChoser = ' <form name="day"><select ONCHANGE=\'location.href="index.php?day="+this.value;\'>';
 $dayChoser = ' <form name="day"><select ONCHANGE=\'location.href="index.php?day="+this.value;\'>';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文