Table of contents
1. If you want to open a new window named "window2", you can use ()
2. Which of the following events is not triggered by the mouse ()
3. Which scope in the Angular directive can inherit the parent scope
4. Which of the following events do not support bubbling? ()
2. It is required to remove the spaces at both ends of the parameter string and return
1. Multiple choice questions
1. If you want to open a new window named "window2", you can use ()
A、open.new("http://www.w3school.com.cn","window2")
B、new.window("http://www.w3school.com.cn","window2")
C、new("http://www.w3school.com.cn","window2")
D、window.open("http://www.w3school.com.cn","window2")
Correct answer: D Your answer: B
Parse:
(1) The window.open(URL,name) method is used to open a new browser window or find a named window
① Parameter 1 (URL) specifies the URL of the opened page, if no URL is specified, a new blank window will be opened
② Parameter 2 (name) specifies the name of the window, which is composed of letters, numbers and underline characters, without spaces
(2) Names with special meanings
①_blank: display the target page in a new window
②_self: display the target webpage in the current window
③_top: The target web page is displayed in the upper window of the frame web page
Note: Only one window with the same name can be created. If you want to create multiple windows, the names cannot be the same
(3) When window.open() has four parameters
①url address
②name
③features: new window information (size, location, etc.)
④ Boolean type: whether to use it as a historical record
<body>
<button id="btn">点击按钮</button>
<script>
document.getElementById('btn').onclick=function(){
newWindow=window.open('https://www.baidu.com/','_blank','left=200px,top=100px,width=500px,height=500px',false)
}
</script>
</body>
2. Which of the following events is not triggered by the mouse ()
A、click
B、contextmenu
C、mouseout
D、keydown
correct answer: D
Parse:
(1) Option analysis
Option A: click is a mouse click event
Option B: contextmenu is an event that is triggered when the viewer presses the right mouse button to display the menu or triggers the page menu through the keyboard [Add onContentMenu="return false" to the <body> of the page to disable the use of the right mouse button up]
Option C: The mouseout event will occur when the mouse pointer moves out of the specified object
Option D: The keydown event will occur when the user presses a keyboard key , triggered by the keyboard
(2) Common events
①Click event
- onclick: click event
- ondblclick: double click event
②Focus event
- onblur lose focus
- onfocus element gets focus
③Load event
- onload A page or an image has finished loading
④Mouse event
- onmousedown mouse button is pressed
- onmouseup mouse button is released
- onmousemove mouse is moved
- onmouseover mouse over an element
- onmouseout The mouse moves away from an element
⑤ Keyboard events
- onkeydown A keyboard key is pressed
- onkeyup A keyboard key is released
- onkeypress A keyboard key is pressed and released
⑥Select and change
- The content of the onchange field is changed
- onselect text is selected
⑦ form event
- onsubmit confirm button is clicked
- onreset reset button is clicked
3. Which scope in the Angular directive can inherit the parent scope
A、scope:true
B、scope:{}
C、scope:parent
D. By default, the parent scope is inherited
Correct answer: A
Parse:
(1) scope: true and transclude: true will create a new sub-scope and carry out prototype inheritance
(2 ) scope: {...} will create a new independent scope without prototype inheritance
(3) By default, creating a directive uses scope: false, and does not create subscopes
4. Which of the following events do not support bubbling? ()
A、resize
B、click
C、blur
D、mouseleave
Correct answer: ACD Your answer: AC
Parse:
Quick memory method that does not support bubbling
"I (unload) mom (mouseenter) mom (mouseleave) don't (blur) let (resize) waste (load) waste (focus)"
2. Programming questions
1. Please complete the JavaScript function, and it is required to convert the string parameter into an object and return it.
示例:typeof string === 'string' -> typeof _stringtoobject(string) === 'object'
Parse:
(1) Method 1: new an instance
<script>
var string = '2sdg'
function _stringtoobject(string) {
return new String(string)
}
console.log(_stringtoobject(string));
</script>
(2) Method 2: Object()
<script>
var string = '2sdg'
function _stringtoobject(string) {
return Object(string)
}
console.log(_stringtoobject(string));
</script>
(3) Method three: {}
<script>
var string = '2sdg'
function _stringtoobject(string) {
return {string}
}
console.log(_stringtoobject(string));
</script>
2. It is required to remove the spaces at both ends of the parameter string and return
Parse:
(1) Method 1: trim()
<script>
var string = ' 2sdg '
function _trim(string){
return string.trim()
}
console.log(_trim(string));
</script>
(2) Method 2: regular expressions
<script>
var string = ' 2sdg '
function _trim(string){
return string.replace(/^\s|\s$/g,"")
}
console.log(_trim(string));
</script>