如何动态启用/创建元素
我使用 PHP、jQuery 和 Spry 的组合来提供一系列列表框,用户将首先选择车辆类型,然后是品牌,然后是型号,最后是特定型号。
我的所有列表框 (SELECT) 都工作正常,并且它们使用 Spry 元素正确更新。每个列表框都由不同的 Spry XML 数据集填充,这是我的问题。
如果我向用户呈现所有四个列表框,则脚本必须获取所有四批 XML 来填充所有四个列表框,这需要几秒钟的时间。我想要做的是按顺序创建/启用列表框,因此当用户从第一个列表框中选择时,会创建/启用第二个列表框,当他们从第二个列表框中选择时,会创建/启用第三个列表框...等等在。
设置禁用属性并不好,因为脚本在处理之前已经获取了 XML。
有什么想法吗?
Si
更新——对不起,大家,我认为我没有把问题说清楚。
在脚本的顶部,我声明了四个 Spry XML 数据集变量,每个变量都会关闭(需要时)并对服务执行复杂的 SOAP 查询,然后该服务返回一块 XML。每个查询都依赖于上一个查询,因此一旦用户选择了车辆类型,第二个数据集就会刷新以提供准确的制造商列表。当他们选择制造商时,第三个列表将刷新以提供该制造商的准确型号列表。当他们选择模型时,该模型的模型衍生列表将刷新(第四个列表)。
在我的脚本的更下方,我有四个 SELECT,每个都填充了来自 spry 查询的数据。现在,用户必须依次从每个列表中选择所需的选项,以便在最终框中获得正确的模型。我想要做的只是在生成页面时填充第一个框,然后当用户在每个框中选择所需的值时填充(或创建?)第二个、第三个和第四个框,就像 Autotrader 网站中发生的情况( www.autotrader.co.uk)。
正如我在最初的帖子中所说,我不能使用“禁用”属性,甚至不能使用 jQuery show() 和 hide() 函数,因为这些函数只有在获取所有四个数据集并将其填充到 SELECT 中之后才会触发。我需要一些理想的东西,可以在需要时从头开始创建元素,以阻止在开始时获取四批 XML...
希望这能澄清
I am using a combination of PHP, jQuery and Spry to serve a series of listboxes in which a user will select first the type of vehicle, then the make, then the model and finally the specific model.
All my listboxes (SELECT) are working fine, and they update properly using the Spry elements. Each listbox is populated from a different Spry XML Dataset, and this is my problem.
If I present all four listboxes to the user, the script has to go and fetch all four lots of XML to populate all four listboxes, taking several seconds. What I want to do is to create/enable the listboxes in order, so at the user selects from the first listbox, the second is created/enabled, when they select from the second, the third is created/enabled... and so on.
Setting the disabled attribute is no good because the script has already fetched the XML before this is processed.
Any ideas??
Si
UPDATE -- Sorry guys, don't think I made my problem quite clear.
At the top of my script I declare four Spry XML data set variables, each of which goes off (when required) and performs a complex SOAP query against a service, this service then returns a chunk of XML. Each query is dependant on the last, so once the user has selected the type of vehicle, the second data set is refreshed to give an accurate list of manufacturers. When they select the manufacturer, the third list is refreshed to give an accurate list of models for that manufacturer. When they select the model, the list of model derivatives is refreshed for that model (fourth list).
Further down my script I have four SELECT's, each of which is populated with the data from the spry queries. Now, the user must choose the desired option from each list in turn in order to get the right model in the final box. What I want to do is ONLY populate the first box when the page is generated, then populate (or create??) the second, third and fourth boxes when the user selects the desired value in each, much like happens in the Autotrader website (www.autotrader.co.uk).
As I said in the initial posting, I can't use the 'disabled' attr, or even the jQuery show() and hide() functions, as these do not fire until AFTER all four datasets have been fetched and populated into the SELECT's. I need something which ideally creates the elements from scratch as and when required, to stop the four lots of XML being fetched at the beginning...
Hope this clarifies
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这完全未经测试,但根据 API,可能有效。我不确定我是否完全理解您的问题,但如果您希望在选择后启用下一个选项并禁用之后的选项,直到单击下一个选项,那么如果它有效,这将是您的票证。
如果需要动态添加(或删除)它们,您只需使用
.after
和.nextAll
方法来添加并精确定位要删除的选择框。更新:哎哟。选择器错误。
This is wholly untested, but according to the API, may work. I'm not sure I understand your question completely, but if you're looking to enable the next option after selection and disable the options after that until the next option is clicked, this is would be your ticket if it works.
If it's a matter of adding (or removing) them dynamically, you can just use the
.after
and.nextAll
methods to add and pinpoint select boxes for removal.UPDATE: Whoopsie. Had the wrong selectors.
与其禁用它们,为什么不直接使用 jQuery 隐藏/显示呢?
.hide()
.show()
,Instead of disabling them, why not just hide/show using jQuery?
.hide()
.show()
,我不确定我知道你在问什么,但你似乎在寻找类似的东西:
我在这里离基地太远了吗?我的意思是,这只是一种基本的方法(可能有十亿个漏洞),但您希望实时更新,对吗?您不希望它在页面加载时获取所有 XML,对吧?您还可以将
$("#select1")
更改为$("#formname select").each(function() {
,然后让它选择.next("select")
在获取 XML 后将其附加到我承认,我从未真正使用过 Spry,我见过它的使用情况,看起来我可以做些什么。我需要使用 jQuery。
I'm not sure I know what you're asking but it seems like you're looking for something like:
Am I way off base here? I mean, that's just a rudimentary way of going about it (and probably has a billion holes), but you want this updating live, right? You don't want it fetching all the XML on page load, right? You could also change
$("#select1")
to$("#formname select").each(function() {
and then have it pick the.next("select")
to append it to after fetching the XML.I'll confess, I've never really used Spry. I've seen it in use a little and it seemed like I could do what I needed to using jQuery.