下拉列表中的动态选定值
我在 for 循环中的 kohana 视图中有一个下拉列表。它看起来像这样:
<? for ($i = 1; $i <= $max; $i++):?>
<option <?= $content->product_type->stock_2 == $i ? 'selected="selected"' :'';?> value="<?= $i ?>"><?= $i; ?></option>
<? endfor; ?>
我的问题是我想在我的列表中始终选择一个动态值 $content->number 。我怎样才能做到这一点?这是一件我看不到的小事。我尝试了 'selected="selected"' :'$content->number' ,但不起作用......
i have a drop down list in a kohana view, in a for loop. it looks like that:
<? for ($i = 1; $i <= $max; $i++):?>
<option <?= $content->product_type->stock_2 == $i ? 'selected="selected"' :'';?> value="<?= $i ?>"><?= $i; ?></option>
<? endfor; ?>
My problem is that i want to have selected a dynamically value, $content->number , always, in my list. How can i make that ? it is a little thing that i don't see. i tried 'selected="selected"' :'$content->number' , but doesn;t work...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,很抱歉这个误导性的答案,但是这是在纯 php 上运行的,所以内容一定有问题。
Well Sorry for the misleading answer, But this is working on plain php so something must be amiss with the content.
如果无法选择超过
$content->product_type->stock_2
,那么您是否不应该迭代直到该数字而不是选择它?If one cannot choose more than
$content->product_type->stock_2
, then shouldn't you iterate until that number instead of selecting it?你说对了。我做了一些小的语法增强。
如果这不是您的意思,请提供更多信息来说明您认为它“不起作用”的原因。
You got it right. I have made a few minor syntax enhancements.
If this is not what you meant, please provide more information as to why you think it's "not working".