Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Как выполнить код на jquery (https://javascript.ru/forum/dom-window/74261-kak-vypolnit-kod-na-jquery.html)

KirillAlekseev 25.06.2018 15:05

Как выполнить код на jquery
 
Всем привет!

Подскажите новичку плз, как можно реализовать ниже указанный скрипт на jquery?

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1F wO5qRGvFXOdJZ4" crossorigin="anonymous">

<title>Hello, world!</title>

<script type="text/javascript">
var tf,ab,mt
		window.onload=function(){
		tf=document.getElementById("message-text");
		ab=document.getElementById("applyButton");
		mt=document.getElementById("text");
		tf.value=""
			ab.onclick=function(){
			mt.innerHTML=tf.value
			}
		}

</script>
</head>
<body>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Open modal for @mdo</button>

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">New message</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="message-text" class="col-form-label">Message:</label>
<textarea class="form-control" id="message-text"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button id="applyButton" type="button" class="btn btn-primary" data-dismiss="modal" >Send message</button>
</div>
</div>
</div>
</div>
<div>Вы ввели строку:</div>
<i id="text"></i>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abt TE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7b uKt/6v9KI65qnm" crossorigin="anonymous"></script>
</body>
</html>

ksa 25.06.2018 15:14

Цитата:

Сообщение от KirillAlekseev
как можно реализовать ниже указанный скрипт на jquery?

Как вариант...

$(function(){
	$('#applyButton').click(function(){
		$('#text').html($('#message-text').val());
	});
});

j0hnik 25.06.2018 15:42

var tf,ab,mt;
window.onload=function(){
tf=$("#message-text");
ab=$("#applyButton");
mt=$("#text");
tf.val('');
	ab.click(function(){
	mt.html(tf.val());
	});
};

KirillAlekseev 25.06.2018 16:54

Цитата:

Сообщение от ksa (Сообщение 488341)
Как вариант...

$(function(){
	$('#applyButton').click(function(){
		$('#text').html($('#message-text').val());
	});
});


ksa


Chrome на 15 (здесь первая) строке выдает ошибку "Uncaught ReferenceError: $ is not defined". Как это можно исправить?

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1F wO5qRGvFXOdJZ4" crossorigin="anonymous">

<title>Hello, world!</title>

<script type="text/javascript">
$(function(){

			$('#applyButton').click(function(){

				$('#text').html($('#message-text').val());

			});

		});

</script>
</head>
<body>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">Open modal for @mdo</button>

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">New message</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="message-text" class="col-form-label">Message:</label>
<textarea class="form-control" id="message-text"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button id="applyButton" type="button" class="btn btn-primary" data-dismiss="modal" >Send message</button>
</div>
</div>
</div>
</div>
<div>Вы ввели строку:</div>
<i id="text"></i>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abt TE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7b uKt/6v9KI65qnm" crossorigin="anonymous"></script>
</body>
</html>

KirillAlekseev 25.06.2018 17:03

Цитата:

Сообщение от j0hnik (Сообщение 488345)
var tf,ab,mt;
window.onload=function(){
tf=$("#message-text");
ab=$("#applyButton");
mt=$("#text");
tf.val('');
	ab.click(function(){
	mt.html(tf.val());
	});
};

Спасибо! Работает!:dance:

ksa 27.06.2018 08:49

Цитата:

Сообщение от KirillAlekseev
выдает ошибку "Uncaught ReferenceError: $ is not defined"

Значит jQuery еще не подключена...


Часовой пояс GMT +3, время: 09:23.