HTML SELECT 中的简单 PHP 不起作用
我正在尝试执行以下代码:
<label for="gender">Gender*: </label>
<select name="user[test]" id="gender">
<? echo "THISISATEST"?>
<option value="-1"> - Select - </option>
</select>
它没有执行任何操作。
然而,这工作得很好:
<select name="user[test]" id="gender">
<option value="-1"> - Select - </option>
</select>
<? echo "THISISATEST"?>
发生了什么事?
谢谢!
编辑:我是个白痴,我试图简化在这里发布的问题,结果回显出现在源中,而我尝试动态创建的行不起作用。德普。我忘记用括号括住我的速记 if?else: ,这导致整行不回显。
谢谢
I'm trying to execute the following code:
<label for="gender">Gender*: </label>
<select name="user[test]" id="gender">
<? echo "THISISATEST"?>
<option value="-1"> - Select - </option>
</select>
And it doesn't do anything.
However, this works fine:
<select name="user[test]" id="gender">
<option value="-1"> - Select - </option>
</select>
<? echo "THISISATEST"?>
What's going on?
Thanks!
Edit: I'm an idiot, I tried to simplify the problem for posting on here, turns out the echoing is appearing in the soruce and the line where I try to dynamically create the just isn't working. Derp. I forgot to surround my shorthand if?else: with brackets, which caused the whole line not to echo.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
而是做
Rather do
这应该可以正常工作。您也可以输入您想要的值
This should work fine. You can enter your desired value as well
您完全确定您的服务器上启用了短标签吗?我只是仔细检查
看看这是否会改善你的运气。另外,您是否查看了源代码 - 因为在选择时该值可能已隐藏在呈现的页面上。
Are you entirely certain short tags are enabled on your server? I'd just double check
<?php echo "THISISATEST"; ?>
and see if that improves your luck. Also, did you view source - because that value may have been hidden on a rendered page when in a select as such.简单的。您的浏览器会忽略
select
节点下的文本节点。这种安排并不在 HTML 规范中,因此浏览器可以随意修改它。Simple. Your browser ignores text nodes under a
select
node. This arrangement is not in the HTML spec, so browsers are free to mutilate it however they like.