该帮助的版本不再更新,请参见https://www.jmp.com/support/help/zh-cn/15.2 获取最新的版本.


You can use the Set Script message to have a display box control (for example, a button box or combo box) run a script when it is clicked with the mouse.
win = New Window( "Set Script Example",
ex = Button Box( "Press me" )
ex << Set Script( Print( "Pressed" ) );
Alternatively, you can use the Set Function message to have a display box control run a specific function where the first argument is the specific display box. Set Function enables you to build more object-oriented scripts and to create a larger system.
win = New Window( "Set Function Example",
Button Box( "Press me",
<< Set Function(
Function(
// functions specified with Set Function get 'this' display box
this << Set Button Name( "Thanks" )
If you have multiple buttons that can be serviced by the same script, Set Function is much simpler than Set Script because it tells you which button was pressed. In this example, both check boxes use the script that begins on the first line.
f = Function( {this, idx}, // idx just changed
Write(
"\!n changing item=" || (this << Get Items())[idx] || " to " || Char( this << Get( idx ) ) ||
"\!n new selection=" || Char( this << Get Selected ) || "\!n"
)// <<Get Selected returns a list of the currently checked (selected) items
New Window( "Example",
H List Box( // 'f' is the 'named' function, used twice
V List Box( Text Box( "Column 1" ), Check Box( {"a", "b"}, <<Set Function( f ) ) ),
Spacer Box( size( 50, 50 ) ),
V List Box( Text Box( "Column 2" ), Check Box( {"c", "d"}, <<Set Function( f ) ) )
In the following example of Set Function, the same function is used to create the buttons.
New Window( "Cash Box",
V List Box(
H Center Box( TB = Text Box() ), // TB will show total of coins
LB = Lineup Box( N Col( 3 ) ), // LB will hold buttons, added below
H Center Box( // CLEAR button will reset the total
Button Box( "CLEAR",
TB << Set Text( Char( total ) );
coins = {1, 5, 10, 25, 50, 100}; // coins is a list of the button labels
For( iButton = 1, iButton <= N Items( coins ), iButton++,
LB << Append( Button Box( Char( coins[iButton] ), Set Function( buttonFunction ) ) )
); /* loop creates the buttons and shows that the same function
buttonFunction = Function( {this},
total = total + Num( this << Get Button Name );
TB << Set Text( Char( total ) );
注意: 
The Set Script and Set Function messages work for button boxes, calendar boxes, check boxes, combo boxes, list boxes, popup boxes, radio boxes, range slider boxes, slider boxes, and spin boxes.
You cannot use both Set Script and Set Function at the same time. Use Set Function if you need to reference a specific display box object.