我需要根据从下拉菜单中选择的tld来获取价格,我使用了以下代码。
找到以下代码:
<div class="form-group">
<label for="inputTransferDomain">Domain Name</label>
<input type="text" class="form-control" name="domain" id="inputTransferDomain" value="" placeholder="example.com" data-toggle="tooltip" data-placement="left" data-trigger="manual" title="" data-original-title="Please enter your domain" required>
</div>
<?php //echo "<pre>";print_r($result['pricing']['com']['transfer']['1']);exit;?>
<select id="tld" class="form-control select_plan" name="name" style="width:95%">
<option value="--Select--">--Select--</option>
@foreach($result['pricing'] as $key=>$value )
<option value="{{$key}}" data-price="{{$result['pricing']['com']['transfer']['1']}}">{{$key}}</option>
@endforeach
</select>
<select name="price" id="price_tld" class="form-control" style="display:none; width: 95%; margin-top: 20px;" >
</select>
</div>
<div class="text-right col-lg-offset-3 col-lg-6 col-sm-12">
<button type="submit" id="btnTransferDomain" class="btn btn-primary btn-transfer center-block">Add to Cart</button>
</div>
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
</form>
我的json数据如下:
Array
(
[com] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 637.70
)
[transfer] => Array
(
[1] => 637.70
)
[renew] => Array
(
[1] => 637.70
)
)
[in] => Array
(
[categories] => Array
(
[0] => ccTLD
[1] => Geography
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 1014.67
)
[transfer] => Array
(
[1] => 1014.67
)
[renew] => Array
(
[1] => 1014.67
)
)
[info] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 200.00
)
[transfer] => Array
(
[1] => 200.00
)
[renew] => Array
(
[1] => 200.00
)
)
[net] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 829.76
)
[transfer] => Array
(
[1] => 829.76
)
[renew] => Array
(
[1] => 829.76
)
)
[biz] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 878.33
)
[transfer] => Array
(
[1] => 878.33
)
[renew] => Array
(
[1] => 878.33
)
)
[org] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 939.45
)
[transfer] => Array
(
[1] => 939.45
)
[renew] => Array
(
[1] => 939.45
)
)
[asia] => Array
(
[categories] => Array
(
[0] => gTLD
[1] => ccTLD
[2] => Geography
[3] => Popular
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 1527.88
)
[transfer] => Array
(
[1] => 1527.88
)
[renew] => Array
(
[1] => 1527.88
)
)
[co.uk] => Array
(
[categories] => Array
(
[0] => ccTLD
[1] => Geography
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 602.53
)
[transfer] => Array
(
[1] => 602.53
)
[renew] => Array
(
[1] => 602.53
)
)
[in.net] => Array
(
[categories] => Array
(
[0] => Other
)
[addons] => Array
(
[dns] => 1
[email] => 1
[idprotect] => 1
)
[group] => sale
[register] => Array
(
[1] => 100.00
)
[transfer] => Array
(
[1] => 100.00
)
[renew] => Array
(
[1] => 100.00
)
)
)
在上面的json数据中,我将tlds设置为[com],[in]等,我需要根据从下拉菜单中选择的tld来显示[转移]下的价格。
找到下面的jquery代码:
$("#tld").on("change", function(){
var selected = $(this).val();
var price = $("#tld option:selected").attr('data-price');
var name=$("#tld option:selected").attr('data-name');
$('#price_tld').show();
$('#price_tld').empty();
$("<option/>").val(price).text(price).appendTo("#price_tld");
});