Метод 1:
$(document).on("click", "p span", function () { // changed p.span to p span(if you're targeting element with class span, you don't need to change this)
$('<div></div>').dialog({
modal: true,
closeText: 'Close',
title: "Title",
open: function () {
var markup = '<p>Text block</p>';
$(this).html(markup);
// remove this line if you don't want to limit it only once
$(document).off('click', 'p span'); // unbind is deprecated, use off instead
}
});
});
<link href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<p><span>Hola Amigo!</span></p>
Метод 2:
$(document).on("click", "p span", function () { // changed p.span to p span(if you're targeting element with class span, you don't need to change this)
// Check the default value
if($(this).attr('data-open') == 0){
$(this).attr('data-open', 1); // Change the default value
$('<div></div>').dialog({
modal: true,
closeText: 'Close',
title: "Title",
open: function () {
var markup = '<p>Text block</p>';
$(this).html(markup);
}
});
}
});
<link href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!-- Add a custom attribute with default value 0 -->
<p><span data-open='0'>Hola Amigo!</span></p>
Посмотрим, поможет ли это вам.