【发布时间】:2018-12-26 05:53:31
【问题描述】:
我正在尝试使用 WKWebView 显示 webView 及其内容。我使用了下面的代码,webView 显示了它的内容。问题是,当单击 webView 中的按钮/文本字段时,有一个功能可以显示自动填充下拉菜单。启用 javascript 后,它在 android 上运行良好,但即使我按照下面的代码启用 javascript,它对我也不起作用。 (参考:https://stackoverflow.com/a/47038285/5416775)
private var webView: WKWebView!
let preferences = WKPreferences()
preferences.javaScriptEnabled = true
let configuration = WKWebViewConfiguration()
configuration.preferences = preferences
webView = WKWebView(frame: view.bounds, configuration: configuration)
php团队使用下面的代码动态显示下拉菜单的功能。
$('input[name=\'option\']').autocomplete({
'source': function(request, response) {
$.ajax({
url: 'index.php?route=product/product_option/autocomplete&language_id=<?php echo $language_id; ?>&store_id=<?php echo $store_id; ?>&filter_name=' + encodeURIComponent(request),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
category: item['category'],
label: item['name'],
value: item['option_id'],
type: item['type'],
option_value: item['option_value']
}
}));
}
});
},
'select': function(item) {
html = '<div class="tab-pane" id="tab-option' + option_row + '">';
html += ' <input type="hidden" name="product_option[' + option_row + '][product_option_id]" value="" />';
html += ' <input type="hidden" name="product_option[' + option_row + '][name]" value="' + item['label'] + '" />';
html += ' <input type="hidden" name="product_option[' + option_row + '][option_id]" value="' + item['value'] + '" />';
html += ' <input type="hidden" name="product_option[' + option_row + '][type]" value="' + item['type'] + '" />';
if (item['type'] == 'checkbox') {
html += ' <div class="form-group">';
html += ' <label class="col-sm-12 control-label text-danger"><?php echo $entry_text_required; ?></label>';
html += ' </div>';
}
html += ' <div class="form-group" style="display: none;">';
html += ' <label class="col-sm-2 control-label" for="input-required' + option_row + '"><?php echo $entry_required; ?></label>';
html += ' <div class="col-sm-10"><select name="product_option[' + option_row + '][required]" id="input-required' + option_row + '" class="form-control">';
html += ' <option value="1"><?php echo $text_yes; ?></option>';
html += ' <option value="0"><?php echo $text_no; ?></option>';
html += ' </select></div>';
html += ' </div>';
html += ' <div class="form-group" style="display: none;">';
html += ' <label class="col-sm-2 control-label" for="input-option-sort-order' + option_row + '"><?php echo $entry_option_sort_order; ?></label>';
var option_row = <?php echo $option_row; ?>;
任何解决方案..?将不胜感激。谢谢..!
【问题讨论】:
-
请分享您的 Html 字符串,其中包含您的下拉菜单
-
检查您的 php 页面的 javascript。它被注释掉了。即不会在任何地方执行
-
@SahilManchanda,因为我是编码新手,所以我无法理解你。能详细解释一下吗?
-
@Saravanan,在桌面上试试你的 url,看看它是否在 select 上显示任何选项
-
我在 FireFox (iMac) 上试过,但没有显示任何选项。
标签: javascript ios swift wkwebview