如何通过trigger()选择特定值

时间:2016-05-23 04:23:39

标签: javascript jquery

enter image description here

在Jquery滑块中,最小值为1,最大值为100

这里,当前值是30,我必须选择值为50 这应该以编程方式完成,例如使用trigger()或任何其他类似的方法。

怎么做?

3 个答案:

答案 0 :(得分:1)

您可以将滑块值设置为30,如:

$( ".selector" ).slider( "option", "value", 30 );

slider API docs的更多信息。

答案 1 :(得分:1)

参考Jquery UI文档JQuery Doc

你有没有试过这样的事情:

$( ".selector" ).slider( "option", "value", 30 );

答案 2 :(得分:0)

如果要在初始化以外的任何时间选择值

override func viewDidLoad()
{
    super.viewDidLoad()

    let screenWidth = self.view.frame.width
    let screenHeight = self.view.frame.height

    let vc0 = self.storyboard?.instantiateViewControllerWithIdentifier("vc0")

    self.addChildViewController(vc0!)
    self.scrollView.addSubview(vc0!.view)
    vc0!.didMoveToParentViewController(self)

    let vc1 = self.storyboard?.instantiateViewControllerWithIdentifier("vc1")

    var frame1 = vc1!.view.frame 
    frame1.origin.x = self.view.frame.size.width
    vc1!.view.frame = frame1

    self.addChildViewController(vc1!)
    self.scrollView.addSubview(vc1!.view)
    vc1!.didMoveToParentViewController(self)

    self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, self.view.frame.size.height);

    //ADD CONSTRAINTS TO vc0

    vc0!.view.translatesAutoresizingMaskIntoConstraints = false
    let horizontalConstraint = NSLayoutConstraint(item: vc0!.view, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: scrollView, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 0)
    view.addConstraint(horizontalConstraint)

    let widthConstraint = NSLayoutConstraint(item: vc0!.view, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: screenWidth)
    view.addConstraint(widthConstraint)

    let heightConstraint = NSLayoutConstraint(item: vc0!.view, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: screenHeight)
    view.addConstraint(heightConstraint)

    //ADD CONSTRAINTS TO vc1

    vc1!.view.translatesAutoresizingMaskIntoConstraints = false
    let horizontalConstraint2 = NSLayoutConstraint(item: vc1!.view, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: vc0!.view, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0)
    view.addConstraint(horizontalConstraint2)

    let widthConstraint2 = NSLayoutConstraint(item: vc1!.view, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: screenWidth)
    view.addConstraint(widthConstraint)

    let heightConstraint2 = NSLayoutConstraint(item: vc1!.view, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: screenHeight)
    view.addConstraint(heightConstraint)
}

JQuery Slider Docs