简体   繁体   English

如何在选项标签中放置包含空格的值?

[英]How to put value containing spaces in option tag?

I need to assign a string to value in option tag, which contains multiple words.我需要为选项标签中的值分配一个字符串,其中包含多个单词。

echo "<option value=".$row['code']." ></option>" ;

I tried it like this, but only one word appears.我是这样试的,但只出现一个字。

The HTML attributes are separated by spaces. HTML 属性由空格分隔。 To specify a value, which contains spaces you need to enclose it in quotes, either single ' or double " .要指定一个包含空格的值,您需要将其括在引号中,可以是单引号'或双引号"

<option value="some value" anotherAttribute=1></option>

Becuase in PHP you have already used double quotes you can use single quotes now to enclose the value of your HTML attribute.因为在 PHP 中您已经使用了双引号,您现在可以使用单引号将 HTML 属性的值括起来。

echo "<option value='".$row['code']."' ></option>" ;

You could also put the value between the tags as the content, if the value and the displayed content is the same.如果值和显示的内容相同,您也可以将标签之间的值作为内容。

echo "<option>".$row['code']."</option>" ;

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

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