这是我的html代码,列表项来自使用foreach循环的数据库:
<select class="form-control select" id="inventoryitem" name="inventoryitem" onchange="getunit();">
<option>---select item---</option>
<?php foreach($item as $i) { ?>
<option><?php echo $i->Name; ?></option>
<?php } ?>
</select>
这是我的脚本代码:
function getunit()
{
var item = $('#inventoryitem').val();
alert(item);
}
答案 0 :(得分:0)
请删除onchange =&#34; getunit();&#34;从你的选择 并尝试以下代码:
$( "#inventoryitem" ).change(function() {
var item = $( "#inventoryitem option:selected" ).text();
alert(item);
});
答案 1 :(得分:0)
如果其中任何一个错误,Javascript将停止运行 请确保您的所有JavaScript都运行正常。
func MapView(mapview: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryTapped control: UIControl!) {
if control == view.rightCalloutAccessoryView {
print(view.annotation?.title)
print(view.annotation?.subtitle)
//Perform segue to navigate to viewcontroller
}
}
func MapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
print("viewForAnnotation")
if(annotation is MKUserLocation) {
return nil
}
let reuseID = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseID) as? MKPinAnnotationView
if(pinView == nil) {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseID)
pinView!.canShowCallout = true
pinView!.animatesDrop = true
}
var button = UIButton(type: .DetailDisclosure) as UIButton
pinView?.rightCalloutAccessoryView = button
return pinView
}