通过读取数据库+循环的方法做了一个select下拉列表,但始终无法通过js赋予指定值,怎么解决?(撒分,不够另补)
想了想,这个和js其实不怎么相关,还是php问题。
问题背景:该页面左边是一些记录的列表,右边是很多空框,供填入一些信息,之后保存。然后点击左边记录的其中一项,相关信息就能在右边出现。上述功能我都已经实现了。
问题:右边很多空框中有一项是select下拉列表进行选择哪辆车。我的做法是从数据库中读取carNum(integer类型),以此作为select中option的value,而显示的值是数据库中对应该车辆的licenseNum(车牌号),上述用php循环的方法查询并且实现的。但我用js指定该id的select的值时,该select一点反应没有。我把这个select换成确定的select(即去除php循环,而是在htm中直接设定value和选项名称),则js可以指定该select的值,并显示出该值。
但我希望能循环设置该select,而且js能指定该值(显然,这样的话就可以动态显示了。)
该如何解决呢? 撒分,不够的话回帖或者私信给我,可另补。
直接上代码:
<!---下面是htm直接设定html的select的代码----><select id="showOrder_21" name="truck" class="dropdown" style="margin-left:0px !important; border:1px solid #BABABA !important;"> <option value ="1">QAZ123</option> <option value ="2">WSX234</option> <option value ="3">EDC345</option> <option value ="4">TGB456</option></select></td>
下面是采用循环的方式实现的select:
<select id="showOrder_21" name="truck" class="dropdown" style="margin-left:0px !important; border:1px solid #BABABA !important;"><?php $query = "select * from transport.truck order by carNum";$data = getAll($query);foreach($data as $each){?><option value="<?php echo $each['carNum']; ?> "><?php echo $each['licNum'];?></option><?php } ?></select></td>
下面是我用的js 部分:
<script type="text/javascript"> $(document).ready(function(){ $(".LeftTask").click(function(){ $(this).css("background","#A8A8A8"); $(this).siblings().css("background","white"); var orderID = $(this).find('input').val(); $.ajax({ type:"get", url:"main/ajax.php", data:{ orderID:orderID }, success:function(msg){ msg = eval("("+msg+")"); <!---当中删除大量不相关的显示---> $("#showOrder_21").val(msg.truck); } }); });}); </script>
大牛们,求指导!!!
怎么解决这个问题呢?求关键代码片段或网上案例,万分感谢!!!
回复讨论(解决方案)
$(".LeftTask").click(function(){
改成
$(".LeftTask").live("click",function(){ .......
后者的优势是可以"即使某dom节点是页面载入完成之后生成的,也能绑定事件".
参阅jquery手册.
$(".LeftTask").click(function(){
改成
$(".LeftTask").live("click",function(){ .......
后者的优势是可以"即使某dom节点是页面载入完成之后生成的,也能绑定事件".
参阅jquery手册.
哇,你来了啊,欢迎欢迎。立马试。
谢谢啊。
另外更好的办法是在动态生成的html标签中使用onclick="xxxxxxxx()"这种形式 好处是不像live那样耗费浏览器资源
$(".LeftTask").click(function(){
改成
$(".LeftTask").live("click",function(){ .......
后者的优势是可以"即使某dom节点是页面载入完成之后生成的,也能绑定事件".
参阅jquery手册.
出错信息:
Line: 408
Error: Object doesn't support property or method 'live'
可能是我在head里面设置的版本问题。
前两天你给我的checkbox中的attr也出错了,最后换成最新版本中prop,才最终成功。
中间多了个空格!
变成了
不出问题才怪呢
中间多了个空格!
变成了
不出问题才怪呢
版主英明,刚才我自己查了很久,也同时发现这个问题。
这样,版主指明问题,再看我一眼一贯支持。
结贴,两位都是熟人,你看这样可否:
版主65分,再看我一眼35分如何?
这样,版主指明问题,再看我一眼一贯支持。
结贴,两位都是熟人,你看这样可否:
版主65分,再看我一眼35分如何?
都是熟人,就暂且这样。有觉得不满意的,可回帖或私信给我。
一再感谢大牛们帮助!!!
分数都是浮云,无所谓的.... 有问题继续交流.... 版大确实犀利 一眼看出问题所在~

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio
