如何在php中获得选择选项标签名称 [英] How to get the select option lable name in php

查看:90
本文介绍了如何在php中获得选择选项标签名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在php中获取选择选项标签名称.在我的代码中选项标签不同.选项值不同.我想获取标签名称.
这是我的代码:

How to get the select option lable name in php.In my code option label is different.option value is different.I want to get the name of the label.
This is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<select name="CATEGORY_ID">
  <option label="[Top]" value="0" selected="selected">[Top]</option>
<option label="|___Arts &amp; Humanities" value="1">|___Arts &amp; Humanities</option>

</body>
</html>

推荐答案

看这段代码,我不确定您了解您想要获得什么以及PHP(或更确切地说是Web)如何工作.您的页面内容与PHP无关,直到您向服务器发送一些HTTP请求为止.您可以执行以下操作之一:1)将控件包装在<form>中,并使用"POST"方法提交整​​个表单;在服务器端处理POST数据,通过<name>属性值识别元素; 2)使用JavaScript读取某些控件的值,并使用AJAX将所需的HTTP请求立即发送到服务器.

两种方法都需要PHP API知识,第二种方法需要JavaScript.请参阅:
http://www.w3schools.com/php/php_post.asp [ http://en.wikipedia.org/wiki/Ajax_%28programming%29 [ ^ ],
http://en.wikipedia.org/wiki/XMLHttpRequest [ http://www.w3schools.com/ajax/default.asp [ http://www.w3schools.com/php/php_ajax_php.asp [ http://www.w3schools.com/js/default.asp [
Looking at this code, I''m not sure you understand what do your want to obtain and how PHP (or rather Web) works. You page content has nothing to do with PHP until you send some HTTP request to the server. You can do one of the following: 1) wrap your control in <form> and submit a whole form with the method "POST"; process the POST data on the server side, recognize elements by their <name> attribute values; 2) use JavaScript to read the value of some controls and AJAX to send required HTTP request to the server immediately.

Both methods require knowledge of PHP API and the second one requires JavaScript. Please see:
http://www.w3schools.com/php/php_post.asp[^],
http://en.wikipedia.org/wiki/Ajax_%28programming%29[^],
http://en.wikipedia.org/wiki/XMLHttpRequest[^],
http://www.w3schools.com/ajax/default.asp[^],
http://www.w3schools.com/php/php_ajax_php.asp[^],
http://www.w3schools.com/js/default.asp[^].

Please consider the articles referenced above as a starting point. Have fun.

—SA


这篇关于如何在php中获得选择选项标签名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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