如何在选项标签中放置包含空格的值? [英] How to put value containing spaces in option tag?

查看:32
本文介绍了如何在选项标签中放置包含空格的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为选项标签中的值分配一个字符串,其中包含多个单词.

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.

推荐答案

HTML 属性用空格分隔.要指定包含空格的值,您需要将其括在引号中,单 ' 或双 ".

The HTML attributes are separated by spaces. 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>

因为在 PHP 中您已经使用了双引号,您现在可以使用单引号将 HTML 属性的值括起来.

Becuase in PHP you have already used double quotes you can use single quotes now to enclose the value of your HTML attribute.

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>" ;

这篇关于如何在选项标签中放置包含空格的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆